﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using DiagramDesigner.Controls;
using System.Collections;
using System.Collections.ObjectModel;

namespace DiagramDesigner
{
    public class ElementContent : ContentControl
    {
        #region ID
        private Guid id;
        public Guid ID
        {
            get { return id; }
        }
        #endregion

        #region BlockProperty

        public static readonly DependencyProperty BlockProperty =
            DependencyProperty.RegisterAttached("Block", typeof(String), typeof(ElementContent));

        public String Block
        {
            get { return (String)base.GetValue(BlockProperty); }
            set { base.SetValue(BlockProperty, value); }
        }

        public static String GetBlock(UIElement element)
        {
            return (String)element.GetValue(BlockProperty);
        }

        public static void SetBlock(UIElement element, String value)
        {
            element.SetValue(BlockProperty, value);
        }

        #endregion

        #region ConstraintsProperty

        public static readonly DependencyProperty ConstraintsProperty =
            DependencyProperty.RegisterAttached("Constraints", typeof(ObservableCollection<Items>), typeof(ElementContent));

        public ObservableCollection<Items> Constraints
        {
            get { return (ObservableCollection<Items>)base.GetValue(ConstraintsProperty); }
            set { base.SetValue(ConstraintsProperty, value); }
        }

        public static ObservableCollection<Items> GetConstraints(UIElement element)
        {
            return (ObservableCollection<Items>)element.GetValue(ConstraintsProperty);
        }

        public static void SetConstraints(UIElement element, ObservableCollection<Items> value)
        {
            element.SetValue(ConstraintsProperty, value);
        }

        #endregion

        #region DefaultValueProperty

        public static readonly DependencyProperty DefaultValueProperty =
            DependencyProperty.RegisterAttached("DefaultValue", typeof(String), typeof(ElementContent));

        public String DefaultValue
        {
            get { return (String)base.GetValue(DefaultValueProperty); }
            set { base.SetValue(DefaultValueProperty, value); }
        }

        public static String GetDefaultValue(UIElement element)
        {
            return (String)element.GetValue(DefaultValueProperty);
        }

        public static void SetDefaultValue(UIElement element, String value)
        {
            element.SetValue(DefaultValueProperty, value);
        }

        #endregion

        #region ElementSchemaTypeProperty

        public static readonly DependencyProperty ElementSchemaTypeProperty =
            DependencyProperty.RegisterAttached("ElementSchemaType", typeof(String), typeof(ElementContent));

        public String ElementSchemaType
        {
            get { return (String)base.GetValue(ElementSchemaTypeProperty); }
            set { base.SetValue(ElementSchemaTypeProperty, value); }
        }

        public static String GetElementSchemaType(UIElement element)
        {
            return (String)element.GetValue(ElementSchemaTypeProperty);
        }

        public static void SetElementSchemaType(UIElement element, String value)
        {
            element.SetValue(ElementSchemaTypeProperty, value);
        }

        #endregion

        #region FinalProperty

        public static readonly DependencyProperty FinalProperty =
            DependencyProperty.RegisterAttached("Final", typeof(String), typeof(ElementContent));

        public String Final
        {
            get { return (String)base.GetValue(FinalProperty); }
            set { base.SetValue(FinalProperty, value); }
        }

        public static String GetFinal(UIElement element)
        {
            return (String)element.GetValue(FinalProperty);
        }

        public static void SetFinal(UIElement element, String value)
        {
            element.SetValue(FinalProperty, value);
        }

        #endregion

        #region FixedValueProperty

        public static readonly DependencyProperty FixedValueProperty =
            DependencyProperty.RegisterAttached("FixedValue", typeof(String), typeof(ElementContent));

        public String FixedValue
        {
            get { return (String)base.GetValue(FixedValueProperty); }
            set { base.SetValue(FixedValueProperty, value); }
        }

        public static String GetFixedValue(UIElement element)
        {
            return (String)element.GetValue(FixedValueProperty);
        }

        public static void SetFixedValue(UIElement element, String value)
        {
            element.SetValue(FixedValueProperty, value);
        }

        #endregion

        #region FormProperty

        public static readonly DependencyProperty FormProperty =
            DependencyProperty.RegisterAttached("Form", typeof(String), typeof(ElementContent));

        public String Form
        {
            get { return (String)base.GetValue(FormProperty); }
            set { base.SetValue(FormProperty, value); }
        }

        public static String GetForm(UIElement element)
        {
            return (String)element.GetValue(FormProperty);
        }

        public static void SetForm(UIElement element, String value)
        {
            element.SetValue(FormProperty, value);
        }

        #endregion

        #region IdProperty

        public static readonly DependencyProperty IdProperty =
            DependencyProperty.RegisterAttached("Id", typeof(String), typeof(ElementContent));

        public String Id
        {
            get { return (String)base.GetValue(IdProperty); }
            set { base.SetValue(IdProperty, value); }
        }

        public static String GetId(UIElement element)
        {
            return (String)element.GetValue(IdProperty);
        }

        public static void SetId(UIElement element, String value)
        {
            element.SetValue(IdProperty, value);
        }

        #endregion

        #region IsAbstractProperty

        public static readonly DependencyProperty IsAbstractProperty =
            DependencyProperty.RegisterAttached("IsAbstract", typeof(String), typeof(ElementContent));

        public String IsAbstract
        {
            get { return (String)base.GetValue(IsAbstractProperty); }
            set { base.SetValue(IsAbstractProperty, value); }
        }

        public static String GetIsAbstract(UIElement element)
        {
            return (String)element.GetValue(IsAbstractProperty);
        }

        public static void SetIsAbstract(UIElement element, String value)
        {
            element.SetValue(IsAbstractProperty, value);
        }

        #endregion

        #region IsNillableProperty

        public static readonly DependencyProperty IsNillableProperty =
            DependencyProperty.RegisterAttached("IsNillable", typeof(String), typeof(ElementContent));

        public String IsNillable
        {
            get { return (String)base.GetValue(IsNillableProperty); }
            set { base.SetValue(IsNillableProperty, value); }
        }

        public static String GetIsNillable(UIElement element)
        {
            return (String)element.GetValue(IsNillableProperty);
        }

        public static void SetIsNillable(UIElement element, String value)
        {
            element.SetValue(IsNillableProperty, value);
        }

        #endregion

        #region LineNumberProperty

        public static readonly DependencyProperty LineNumberProperty =
            DependencyProperty.RegisterAttached("LineNumber", typeof(String), typeof(ElementContent));

        public String LineNumber
        {
            get { return (String)base.GetValue(LineNumberProperty); }
            set { base.SetValue(LineNumberProperty, value); }
        }

        public static String GetLineNumber(UIElement element)
        {
            return (String)element.GetValue(LineNumberProperty);
        }

        public static void SetLineNumber(UIElement element, String value)
        {
            element.SetValue(LineNumberProperty, value);
        }

        #endregion

        #region LinePositionProperty

        public static readonly DependencyProperty LinePositionProperty =
            DependencyProperty.RegisterAttached("LinePosition", typeof(String), typeof(ElementContent));

        public String LinePosition
        {
            get { return (String)base.GetValue(LinePositionProperty); }
            set { base.SetValue(LinePositionProperty, value); }
        }

        public static String GetLinePosition(UIElement element)
        {
            return (String)element.GetValue(LinePositionProperty);
        }

        public static void SetLinePosition(UIElement element, String value)
        {
            element.SetValue(LinePositionProperty, value);
        }

        #endregion

        #region MaxOccursProperty

        public static readonly DependencyProperty MaxOccursProperty =
            DependencyProperty.RegisterAttached("MaxOccurs", typeof(String), typeof(ElementContent));

        public String MaxOccurs
        {
            get { return (String)base.GetValue(MaxOccursProperty); }
            set { base.SetValue(MaxOccursProperty, value); }
        }

        public static String GetMaxOccurs(UIElement element)
        {
            return (String)element.GetValue(MaxOccursProperty);
        }

        public static void SetMaxOccurs(UIElement element, String value)
        {
            element.SetValue(MaxOccursProperty, value);
        }

        #endregion

        #region MinOccursProperty

        public static readonly DependencyProperty MinOccursProperty =
            DependencyProperty.RegisterAttached("MinOccurs", typeof(String), typeof(ElementContent));

        public String MinOccurs
        {
            get { return (String)base.GetValue(MinOccursProperty); }
            set { base.SetValue(MinOccursProperty, value); }
        }

        public static String GetMinOccurs(UIElement element)
        {
            return (String)element.GetValue(MinOccursProperty);
        }

        public static void SetMinOccurs(UIElement element, String value)
        {
            element.SetValue(MinOccursProperty, value);
        }

        #endregion

        #region NameProperty

        public static readonly DependencyProperty NameProperty =
            DependencyProperty.RegisterAttached("Name", typeof(String), typeof(ElementContent));

        public String Name
        {
            get { return (String)base.GetValue(NameProperty); }
            set { base.SetValue(NameProperty, value); }
        }

        public static String GetName(UIElement element)
        {
            return (String)element.GetValue(NameProperty);
        }

        public static void SetName(UIElement element, String value)
        {
            element.SetValue(NameProperty, value);
        }

        #endregion

        #region NamespacesProperty

        public static readonly DependencyProperty NamespacesProperty =
            DependencyProperty.RegisterAttached("Namespaces", typeof(ObservableCollection<Items>), typeof(ElementContent));

        public ObservableCollection<Items> Namespaces
        {
            get { return (ObservableCollection<Items>)base.GetValue(NamespacesProperty); }
            set { base.SetValue(NamespacesProperty, value); }
        }

        public static ObservableCollection<Items> GetNamespaces(UIElement element)
        {
            return (ObservableCollection<Items>)element.GetValue(NamespacesProperty);
        }

        public static void SetNamespaces(UIElement element, ObservableCollection<Items> value)
        {
            element.SetValue(NamespacesProperty, value);
        }

        #endregion

        #region ParentProperty

        public static readonly DependencyProperty ParentProperty =
            DependencyProperty.RegisterAttached("Parent", typeof(String), typeof(ElementContent));

        public String Parent
        {
            get { return (String)base.GetValue(ParentProperty); }
            set { base.SetValue(ParentProperty, value); }
        }

        public static String GetParent(UIElement element)
        {
            return (String)element.GetValue(ParentProperty);
        }

        public static void SetParent(UIElement element, String value)
        {
            element.SetValue(ParentProperty, value);
        }

        #endregion

        #region QualifiedNameProperty

        public static readonly DependencyProperty QualifiedNameProperty =
            DependencyProperty.RegisterAttached("QualifiedName", typeof(String), typeof(ElementContent));

        public String QualifiedName
        {
            get { return (String)base.GetValue(QualifiedNameProperty); }
            set { base.SetValue(QualifiedNameProperty, value); }
        }

        public static String GetQualifiedName(UIElement element)
        {
            return (String)element.GetValue(QualifiedNameProperty);
        }

        public static void SetQualifiedName(UIElement element, String value)
        {
            element.SetValue(QualifiedNameProperty, value);
        }

        #endregion

        #region RefNameProperty

        public static readonly DependencyProperty RefNameProperty =
            DependencyProperty.RegisterAttached("RefName", typeof(String), typeof(ElementContent));

        public String RefName
        {
            get { return (String)base.GetValue(RefNameProperty); }
            set { base.SetValue(RefNameProperty, value); }
        }

        public static String GetRefName(UIElement element)
        {
            return (String)element.GetValue(RefNameProperty);
        }

        public static void SetRefName(UIElement element, String value)
        {
            element.SetValue(RefNameProperty, value);
        }

        #endregion

        #region SchemaTypeProperty

        public static readonly DependencyProperty SchemaTypeProperty =
            DependencyProperty.RegisterAttached("SchemaType", typeof(String), typeof(ElementContent));

        public String SchemaType
        {
            get { return (String)base.GetValue(SchemaTypeProperty); }
            set { base.SetValue(SchemaTypeProperty, value); }
        }

        public static String GetSchemaType(UIElement element)
        {
            return (String)element.GetValue(SchemaTypeProperty);
        }

        public static void SetSchemaType(UIElement element, String value)
        {
            element.SetValue(SchemaTypeProperty, value);
        }

        #endregion

        #region SchemaTypeNameProperty

        public static readonly DependencyProperty SchemaTypeNameProperty =
            DependencyProperty.RegisterAttached("SchemaTypeName", typeof(String), typeof(ElementContent));

        public String SchemaTypeName
        {
            get { return (String)base.GetValue(SchemaTypeNameProperty); }
            set { base.SetValue(SchemaTypeNameProperty, value); }
        }

        public static String GetSchemaTypeName(UIElement element)
        {
            return (String)element.GetValue(SchemaTypeNameProperty);
        }

        public static void SetSchemaTypeName(UIElement element, String value)
        {
            element.SetValue(SchemaTypeNameProperty, value);
        }

        #endregion

        #region SourceUriProperty

        public static readonly DependencyProperty SourceUriProperty =
            DependencyProperty.RegisterAttached("SourceUri", typeof(String), typeof(ElementContent));

        public String SourceUri
        {
            get { return (String)base.GetValue(SourceUriProperty); }
            set { base.SetValue(SourceUriProperty, value); }
        }

        public static String GetSourceUri(UIElement element)
        {
            return (String)element.GetValue(SourceUriProperty);
        }

        public static void SetSourceUri(UIElement element, String value)
        {
            element.SetValue(SourceUriProperty, value);
        }

        #endregion

        #region SubstitutionGroupProperty

        public static readonly DependencyProperty SubstitutionGroupProperty =
            DependencyProperty.RegisterAttached("SubstitutionGroup", typeof(String), typeof(ElementContent));

        public String SubstitutionGroup
        {
            get { return (String)base.GetValue(SubstitutionGroupProperty); }
            set { base.SetValue(SubstitutionGroupProperty, value); }
        }

        public static String GetSubstitutionGroup(UIElement element)
        {
            return (String)element.GetValue(SubstitutionGroupProperty);
        }

        public static void SetSubstitutionGroup(UIElement element, String value)
        {
            element.SetValue(SubstitutionGroupProperty, value);
        }

        #endregion

        #region UnhandledAttributesProperty

        public static readonly DependencyProperty UnhandledAttributesProperty =
            DependencyProperty.RegisterAttached("UnhandledAttributes", typeof(ObservableCollection<Items>), typeof(ElementContent));

        public ObservableCollection<Items> UnhandledAttributes
        {
            get { return (ObservableCollection<Items>)base.GetValue(UnhandledAttributesProperty); }
            set { base.SetValue(UnhandledAttributesProperty, value); }
        }

        public static ObservableCollection<Items> GetUnhandledAttributes(UIElement element)
        {
            return (ObservableCollection<Items>)element.GetValue(UnhandledAttributesProperty);
        }

        public static void SetUnhandledAttributes(UIElement element, ObservableCollection<Items> value)
        {
            element.SetValue(UnhandledAttributesProperty, value);
        }

        #endregion

        static ElementContent()
        {
            // set the key to reference the style for this control
            FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
                typeof(ElementContent), new FrameworkPropertyMetadata(typeof(ElementContent)));
        }

        public ElementContent(Guid id)
        {
            this.id = id;
        }

        public ElementContent()
            : this(Guid.NewGuid())
        {
            this.Style = FindResource("DesignerItemContentXsdElementDefaultStyle") as Style;
            this.ApplyTemplate();
            this.SetEventHandlers();
        }

        public ElementContent(string contentTemplateName)
            : this(Guid.NewGuid())
        {
            this.Style = FindResource(contentTemplateName) as Style;
            this.ApplyTemplate();
            this.SetEventHandlers();
        }

        private void SetEventHandlers()
        {

        }

        public void DisableContentControl(String name)
        {
            this.ApplyTemplate();
            Control control = this.Template.FindName(name, this) as Control;
            control.Visibility = Visibility.Collapsed;
        }

        public void EnableContentControl(String name)
        {
            this.ApplyTemplate();
            Control control = this.Template.FindName(name, this) as Control;
            control.Visibility = Visibility.Visible;
        }
    }
}